package com.payment.web.controller.system;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.payment.common.annotation.Log;
import com.payment.common.base.AjaxResult;
import com.payment.common.enums.BusinessType;
import com.payment.common.page.TableDataInfo;
import com.payment.common.utils.ExcelUtil;
import com.payment.framework.util.ShiroUtils;
import com.payment.framework.web.base.BaseController;
import com.payment.system.domain.ResourcesType;
import com.payment.system.service.IResourcesTypeService;


/**
 * 资源类型 信息操作处理
 * 
 * @author payment
 * @date 2019-01-24
 */
@Controller
@RequestMapping("/system/resourcesType")
public class ResourcesTypeController extends BaseController
{
    private String prefix = "system/resourcesType";
	
	@Autowired
	private IResourcesTypeService resourcesTypeService;
	
	@RequiresPermissions("system:resourcesType:view")
	@GetMapping()
	public String resourcesType()
	{
	    return prefix + "/resourcesType";
	}
	
	/**
	 * 查询资源类型列表
	 */
	@RequiresPermissions("system:resourcesType:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ResourcesType resourcesType)
	{
		startPage();
        List<ResourcesType> list = resourcesTypeService.selectResourcesTypeList(resourcesType);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出资源类型列表
	 */
	@RequiresPermissions("system:resourcesType:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ResourcesType resourcesType)
    {
    	List<ResourcesType> list = resourcesTypeService.selectResourcesTypeList(resourcesType);
        ExcelUtil<ResourcesType> util = new ExcelUtil<ResourcesType>(ResourcesType.class);
        return util.exportExcel(list, "resourcesType");
    }
	
	/**
	 * 新增资源类型
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存资源类型
	 */
	@RequiresPermissions("system:resourcesType:add")
	@Log(title = "资源类型", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ResourcesType resourcesType)
	{
		resourcesType.setCreateBy(ShiroUtils.getLoginName());
		return toAjax(resourcesTypeService.insertResourcesType(resourcesType));
	}

	/**
	 * 修改资源类型
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		ResourcesType resourcesType = resourcesTypeService.selectResourcesTypeById(id);
		mmap.put("resourcesType", resourcesType);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存资源类型
	 */
	@RequiresPermissions("system:resourcesType:edit")
	@Log(title = "资源类型", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ResourcesType resourcesType)
	{
		resourcesType.setUpdateBy(ShiroUtils.getLoginName());
		return toAjax(resourcesTypeService.updateResourcesType(resourcesType));
	}
	
	/**
	 * 删除资源类型
	 */
	@RequiresPermissions("system:resourcesType:remove")
	@Log(title = "资源类型", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(resourcesTypeService.deleteResourcesTypeByIds(ids));
	}


	/**
	 * 校验字典类型
	 */
	@PostMapping("/checkTypeUnique")
	@ResponseBody
	public String checkTypeUnique(ResourcesType resourcesType)
	{
		return resourcesTypeService.checkTypeUnique(resourcesType);
	}

	//详情列表
	@GetMapping("/detail/{id}")
	public String detail(@PathVariable("id") Long id, ModelMap mmap)
	{
		mmap.put("resourcesType", resourcesTypeService.selectResourcesTypeById(id));
		mmap.put("resourcesTypeList", resourcesTypeService.selectResourcesTypeAll());
		return prefix +"/resourcesData/resourcesData";
	}
}
